package com.otoe.dilidilivid.data.dao;

import com.otoe.dilidilivid.data.entity.Favorites;
import com.otoe.dilidilivid.data.entity.User;
import com.otoe.dilidilivid.data.operation.MysqlOperation;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class FavDao {

    public List<Favorites> selectAll(){
        List<Favorites> favoritesList=new ArrayList<>();
        try {
            Connection connection = MysqlOperation.DBUtils.getConnect();
            if(connection!=null){
                String sql="select * from FAVORITES";
                PreparedStatement ps= connection.prepareStatement(sql);
                if(ps!=null){
                    ResultSet rs=ps.executeQuery();
                    while (rs.next()){
                        Favorites favorite=new Favorites();
                        favorite.setF_id(rs.getInt(1));
                        favorite.setF_name(rs.getString(2));
                        favorite.setSize(rs.getInt(3));
                        favoritesList.add(favorite);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return favoritesList;
    }
}
